package com.rede.didiok.admin.restapi.admin;


import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.admin.annotion.AuthorityVerify.AuthorityVerify;
import com.rede.didiok.admin.annotion.OperationLogger.OperationLogger;
import com.rede.didiok.admin.support.MomentCommentSupport;
import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.community.MomentCommentDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.feign.CommunityFeignClient;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;

/**
 * 评论表 RestApi
 *
 * @author Rede
 * @since 2023年10月20日16:44:25
 */
@Api(value = "用户评论相关接口", tags = {"用户评论相关接口"})
@RestController
@RequestMapping("/admin/momentComment")
@Slf4j
public class MomentCommentRestApi {

    @Autowired
    CommunityFeignClient communityFeignClient;

    @Autowired
    MomentCommentSupport momentCommentSupport;

    @AuthorityVerify
    @ApiOperation(value = "获取评论列表", notes = "获取评论列表", response = String.class)
    @PostMapping(value = "/getList")
    public String getList(@Validated({GetList.class}) @RequestBody MomentCommentDto momentCommentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取评论列表: {}", momentCommentDto);
        return communityFeignClient.getCommentPageList(momentCommentDto);
    }

    @AvoidRepeatableCommit
    @AuthorityVerify
    @ApiOperation(value = "增加评论", notes = "增加评论", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody MomentCommentDto momentCommentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("新增评论: {}", momentCommentDto);
        return communityFeignClient.addComment(momentCommentDto);
    }

    @AuthorityVerify
    @ApiOperation(value = "编辑评论", notes = "编辑评论", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody MomentCommentDto momentCommentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑评论: {}", momentCommentDto);
        return communityFeignClient.editComment(momentCommentDto);
    }

    @AuthorityVerify
    @ApiOperation(value = "删除评论", notes = "删除评论", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody MomentCommentDto momentCommentDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("删除评论: {}", momentCommentDto);
        return communityFeignClient.deleteComment(momentCommentDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除选中评论")
    @ApiOperation(value = "删除选中评论", notes = "删除选中评论", response = String.class)
    @PostMapping("/deleteBatch")
    public String deleteBatch(@Validated({Delete.class}) @RequestBody List<MomentCommentDto> commentDtoList, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        return communityFeignClient.deleteBatchComment(commentDtoList);
    }

    @AuthorityVerify
    @OperationLogger(value = "审核评论")
    @ApiOperation(value = "审核评论", notes = "审核评论", response = String.class)
    @PostMapping("/audit")
    public String audit(@RequestBody  MomentCommentDto momentCommentDto) {
        return momentCommentSupport.auditComment(momentCommentDto);
    }


}

